import 'package:flutter/material.dart';

class DetailPage extends StatelessWidget {
  const DetailPage({super.key});

  @override
  Widget build(BuildContext context) {
    // 接收上一页传递过来的参数
    final String? title = ModalRoute.of(context)?.settings.arguments as String?;
    return Scaffold(
      appBar: AppBar(
        title: const Text('DetailPage'),
      ),
      body: Center(
        child: Column(
          children: [
            const Text('DetailPage'),
            ElevatedButton(
              onPressed: () {
                // 返回上一页
                Navigator.pop(context);
              },
              child: const Text('返回'),
            ),
            ElevatedButton(
                onPressed: () {
                  // 点击弹窗(可以理解为：在路由中添加一个弹窗页面)
                  showDialog(
                    context: context,
                    builder: (context) {
                      return AlertDialog(
                        title: const Text('温馨提示'),
                        content: const Text('雪天路滑'),
                        actions: [
                          TextButton(
                            onPressed: () {
                              // 关闭弹窗：也是 Navigator.pop(context)
                              Navigator.pop(context);
                            },
                            child: const Text('确定'),
                          ),
                        ],
                      );
                    },
                  );
                },
                child: const Text('返回'))
          ],
        ),
      ),
    );
  }
}
